Full source code website bán hàng thương mại điện tử gần giống shopee
468.260 lượt xem;
1 <?php
2 ###### db ##########
3 $db_username = 'root';
4 $db_password = '';
5 $db_name = 'data';
6 $db_host = 'localhost';
7 ################
8
9
10 //check we have username post var
11 if(isset($_POST["username"]))
12 {
13 //check if its ajax request, exit script if its not
14 if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
15 die();
16 }
17
18 //try connect to db
19 $connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
20
21 //trim and lowercase username
22 $username = strtolower(trim($_POST["username"]));
23
24 //sanitize username
25 $username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
26
27 //check username in db
28 $results = mysqli_query($connecDB,"SELECT user FROM thanhvien WHERE user='$username'");
29
30 //return total count
31 $username_exist = mysqli_num_rows($results); //total records
32
33 //if value is more than 0, username is not available
34 if($username_exist) {
35 die('<b style="color:red;">Tên tài khoản đã có người sử dụng, vui lòng chọn tên khác</b>');
36 }else{
37 die('<b style="color:blue;">Tên tài khoản có thể sử dụng</b>');
38 }
39
40 //close db connection
41 mysqli_close($connecDB);
42 }
43 ?>
2 ###### db ##########
3 $db_username = 'root';
4 $db_password = '';
5 $db_name = 'data';
6 $db_host = 'localhost';
7 ################
8
9
10 //check we have username post var
11 if(isset($_POST["username"]))
12 {
13 //check if its ajax request, exit script if its not
14 if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
15 die();
16 }
17
18 //try connect to db
19 $connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
20
21 //trim and lowercase username
22 $username = strtolower(trim($_POST["username"]));
23
24 //sanitize username
25 $username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
26
27 //check username in db
28 $results = mysqli_query($connecDB,"SELECT user FROM thanhvien WHERE user='$username'");
29
30 //return total count
31 $username_exist = mysqli_num_rows($results); //total records
32
33 //if value is more than 0, username is not available
34 if($username_exist) {
35 die('<b style="color:red;">Tên tài khoản đã có người sử dụng, vui lòng chọn tên khác</b>');
36 }else{
37 die('<b style="color:blue;">Tên tài khoản có thể sử dụng</b>');
38 }
39
40 //close db connection
41 mysqli_close($connecDB);
42 }
43 ?>